<?php

namespace App\Store\Validate\Wxapp\WxappCoupon;

use App\Common\Validate\BaseValidate;

/**
 * 权限组验证器
 */
class WxappCoupon extends BaseValidate
{

    //验证规则
    protected $rule = [];
    //自定义验证信息
    protected $message = [];
    

    public function __construct($doaction = 'add')
    {

        if ($doaction == 'add') {
            $this->rule = [
                'img_path'=>'required',
                'stock_name'=>'required',
                'goods_name'=>'required',
                'stock_type' => 'required|in:NORMAL,DISCOUNT',
                'available_begin_time' => 'required',
                'available_end_time' => 'required',
                'transaction_minimum' => 'required|integer|gt:0',
                'max_coupons_per_user' => 'required|integer|gt:0|lt:100',
                'coupon_code_count' => 'required|integer|gt:0|lt:1000000000',
            ];
            $this->message = [
                'img_path.required' => '券图片未上传',
                'stock_name.required' => '批次名称不能为空',
                'goods_name.required' => '适用范围不能为空',
                'stock_type.required' => '券类型未选择',
                'stock_type.in' => '券类型参数错误',
                'available_begin_time.required' => '使用开始时间不能为空',
                'available_end_time.integer' => '使用结束时间不能为空',
                'transaction_minimum.required' => '消费门槛不能为空',
                'transaction_minimum.integer' => '消费门槛需大于0',
                'transaction_minimum.gt' => '消费门槛需大于0',
                'max_coupons_per_user.required' => '用户可领个数不能为空',
                'max_coupons_per_user.integer' => '用户可领个数需为大于0整数',
                'max_coupons_per_user.gt' => '用户可领个数需为大于0整数',
                'max_coupons_per_user.lt' => '用户可领个数需为小于100整数',


                'coupon_code_count.required' => '卡券数量不能为空',
                'coupon_code_count.integer' => '卡券数量需为大于0整数',
                'coupon_code_count.gt' => '卡券数量需为大于0整数',
                'coupon_code_count.lt' => '卡券数量需为小于1000000000整数',
            ];
        } elseif ($doaction == 'edit') {
            $this->rule = [
                'id' => 'required|integer|gt:0',
                'img_path'=>'required',
                'stock_name'=>'required',
                'goods_category_ids'=>'required',
                'goods_name'=>'required',
                'stock_type' => 'required|in:NORMAL,DISCOUNT',
                'available_begin_time' => 'required',
                'available_end_time' => 'required',
                'transaction_minimum' => 'required|integer|gt:0',
                'max_coupons_per_user' => 'required|integer|gt:0|lt:100',
                'coupon_code_count' => 'required|integer|gt:0|lt:1000000000',
            ];
            $this->message = [
                'id.required' => '参数错误',
                'id.integer' => '参数错误',
                'id.gt' => '参数错误',
                'img_path.required' => '券图片未上传',
                'stock_name.required' => '批次名称不能为空',
                'goods_category_ids.required' => '礼品名称不能为空',
                'goods_name.required' => '适用范围不能为空',
                'stock_type.required' => '券类型未选择',
                'stock_type.in' => '券类型参数错误',
                'available_begin_time.required' => '使用开始时间不能为空',
                'available_end_time.integer' => '使用结束时间不能为空',
                'transaction_minimum.required' => '消费门槛不能为空',
                'transaction_minimum.integer' => '消费门槛需大于0',
                'transaction_minimum.gt' => '消费门槛需大于0',
                'max_coupons_per_user.required' => '用户可领个数不能为空',
                'max_coupons_per_user.integer' => '用户可领个数需为大于0整数',
                'max_coupons_per_user.gt' => '用户可领个数需为大于0整数',
                'max_coupons_per_user.lt' => '用户可领个数需为小于100整数',


                'coupon_code_count.required' => '卡券数量不能为空',
                'coupon_code_count.integer' => '卡券数量需为大于0整数',
                'coupon_code_count.gt' => '卡券数量需为大于0整数',
                'coupon_code_count.lt' => '卡券数量需为小于1000000000整数',
            ];
        }
    }
}
